import { deleteByPrimaryKeyForProSystem, selectByPrimaryKeyForProSystem, insertForProSystem, updateForProSystem, deleteByMapForProSystem,updateByMapForProSystem, getOneForProSystem,getAllForProSystem,queryPageForProSystem, countForProSystem, insertBatchForProSystem, deleteBatchForProSystem,updateBatchForProSystem } from '@/services/system/api_prosystem';

export default {
    namespace: 'prosystem',

    state: {
        data: {
            list: [],
            pagination: {},
        },
    },

    effects: {
            *delete_by_primarykey_for_prosystem({ payload }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProSystem, payload);
                yield put({
                    type: 'deleteByPrimaryKeyForProSystem',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProSystem, {});
                yield put({
                type: 'queryPageForProSystem',
                payload: responsedata,
                });


            },
            *select_by_primarykey_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProSystem, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProSystem',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProSystem, {});
                yield put({
                type: 'queryPageForProSystem',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *insert_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(insertForProSystem, payload);
                yield put({
                    type: 'insertForProSystem',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProSystem, {});
                yield put({
                type: 'queryPageForProSystem',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(updateForProSystem, payload);
                yield put({
                    type: 'updateForProSystem',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProSystem, {});
                yield put({
                type: 'queryPageForProSystem',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *delete_by_map_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProSystem, payload);
                yield put({
                    type: 'deleteByMapForProSystem',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProSystem, {});
                yield put({
                type: 'queryPageForProSystem',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_by_map_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProSystem, payload);
                yield put({
                    type: 'updateByMapForProSystem',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProSystem, {});
                yield put({
                type: 'queryPageForProSystem',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_one_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProSystem, payload);
                yield put({
                    type: 'getOneForProSystem',
                    payload: response,
                });


                if (callback) callback();
            },
            *get_all_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProSystem, payload);
                yield put({
                    type: 'getAllForProSystem',
                    payload: response,
                });

                if (callback) callback();
            },
            *query_page_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProSystem, payload);
                yield put({
                    type: 'queryPageForProSystem',
                    payload: response,
                });


                if (callback) callback();
            },
            *count_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(countForProSystem, payload);
                yield put({
                    type: 'countForProSystem',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_batch_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProSystem, payload);
                yield put({
                    type: 'insertBatchForProSystem',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProSystem, {});
                yield put({
                type: 'queryPageForProSystem',
                payload: responsedata,
                });


                if (callback) callback();
            },
            *delete_batch_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProSystem, payload);
                yield put({
                    type: 'deleteBatchForProSystem',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProSystem, {});
                yield put({
                type: 'queryPageForProSystem',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_batch_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProSystem, payload);
                yield put({
                    type: 'updateBatchForProSystem',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProSystem, {});
                yield put({
                type: 'queryPageForProSystem',
                payload: responsedata,
                });

                if (callback) callback();
            },
            },

    reducers: {
        deleteByPrimaryKeyForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
    },
};
